<?php
/**
 * Created by PhpStorm.
 * User: mabao
 * 消息：系统消息和聊天消息和聊天
 */
namespace app\api\controller;
use think\Db;
use think\Config;
class Map extends Base
{
    /**
     * 异地登录验证
     * @return string|void
     */
    public function _initialize()
    {
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            echo json_encode(['status'=>301,'msg'=>"Token失效！请重新登录！"]);
            exit;
        }
    }
    /**
     * 地图找房：第一级获取本市里区的房源数量
     */
    public function getQu()
    {
        extract(input());
        $where['h_shi'] = $shi;
        $where['h_type'] = $type;
        $where['h_status'] = 1;
        $data = Db::table('up_house')->alias('h')
            ->join('up_area a','h.h_qu=a.district_id','LEFT')
            ->where($where)
            ->group('h_qu')
            ->field('h_shi,h_qu,h_street,h_type,h_qu,h_lat,h_lon,district,count(h_id) number')
            ->select();
        $jiedao = Db::table('up_house')->alias('h')
            ->join('up_area a','h.h_street=a.district_id','LEFT')
            ->where($where)
            ->group('h_street')
            ->field('h_shi,h_qu,h_street,h_type,h_qu,h_lat,h_lon,district,count(h_id) number')
            ->select();
        $xiaoqu = Db::table('up_house')->alias('h')
            ->join('up_area a','h.h_shi=a.district_id','LEFT')
            ->where($where)
            ->group('h_street,h_xiaoqu')
//            ->field('h_shi,h_qu,h_street,h_type,h_qu,h_lat,h_lon,h_xiaoqu,count(h_id) number')
            ->field('h_shi,h_qu,h_street,h_type,h_qu,h_lat,h_lon,h_xiaoqu,avg(h_price) price,avg(h_mianji) mianji,count(h_id) number,district')
            ->select();
        return json(['status'=>200,'msg'=>$data,'jiedao'=>$jiedao,'xiaoqu'=>$xiaoqu]);
    }
    /**
     * 地图找房：第二级获取本市里区的街道的房源数量
     */
    public function getStreet()
    {
        extract(input());
//        $where['h_shi'] = $shi;
        $where['h_type'] = $type;
        $where['h_status'] = 1;
        $where['h_qu'] = $qu;
        $data = Db::table('up_house')->alias('h')
            ->join('up_area a','h.h_street=a.district_id','LEFT')
            ->where($where)
            ->group('h_street')
            ->field('h_shi,h_type,h_qu,h_street,h_lat,h_lon,district,count(h_id) number')
            ->select();
        return json(['status'=>200,'msg'=>$data]);

    }
    /**
     * 地图找房：第三级获取本市里区的街道的小区的房源信息
     */
    public function getVillage()
    {
        extract(input());
//        $where['h_shi'] = $shi;
        $where['h_type'] = $type;
        $where['h_status'] = 1;
//        $where['h_qu'] = $qu;
        $where['h_street'] = $street;
        $data = Db::table('up_house')
            ->where($where)
            ->group('h_street,h_xiaoqu')
            ->field('h_shi,h_type,h_qu,h_street,h_lat,h_lon,h_xiaoqu,avg(h_price) price,avg(h_mianji) mianji,count(h_id) number')
            ->select();
        return json(['status'=>200,'msg'=>$data]);
    }

    /**
     * 地图找房：获取本市里区的街道的某小区的房源列表
     *
     */
    public function getHouse()
    {
        extract(input());
        $where['h_type'] = $type;
        $where['h_status'] = 1;
        $where['h_street'] = $street;
        $where['h_xiaoqu'] = $xiaoqu;
        $data = Db::table('up_house')->alias('h')
            ->join('up_area a','h.h_shi=a.district_id','LEFT')
            ->where($where)
            ->field(['h_id','h_title','h_xiaoqu','h_price','h_shis','h_tings','h_mianji','h_img','district'])
            ->order('h_time DESC')
            ->page($page,10)
            ->select();




        $more = Db::table('up_house')
            ->where($where)
            ->group('h_xiaoqu')
            ->field('avg(h_price) price,avg(h_mianji) mianji,count(h_id) number')
            ->find();
        return json(['status'=>200,'msg'=>$data,'more'=>$more]);
    }



}